/**
 * 
 */
package com.acme.bankapp;

import com.acme.bankapp.domain.bank.Account;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.CheckingAccount;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.bank.Gender;
import com.acme.bankapp.domain.bank.SavingAccount;
import com.acme.bankapp.service.bank.BankService;

/**
 * @author Labun Konstantin
 * 
 */
public class BankApplication {

    protected static final Account[] accounts;
    protected static final String CLIENT_1_NAME = "Petrov";
    protected static final String CLIENT_2_NAME = "Pugacheva";
    protected static final String CLIENT_3_NAME = "Kirkorov";
    protected static final String CLIENT_4_NAME = "Pirozhkov";
    protected static final String CLIENT_5_NAME = "Medvedev";
    protected static final Client[] clients;
    static {
	accounts = new Account[] { new SavingAccount(140000.20),
		new SavingAccount(2662.72),
		new CheckingAccount(9523.14, 13000), new SavingAccount(0.2),
		new CheckingAccount(0.0, 95000.0) };
	clients = new Client[] {
		new Client(CLIENT_1_NAME, Gender.MALE, accounts[0]),
		new Client(CLIENT_2_NAME, Gender.FEMALE, accounts[1]),
		new Client(CLIENT_3_NAME, Gender.MALE, accounts[2]),
		new Client(CLIENT_4_NAME, Gender.MALE, accounts[3]),
		new Client(CLIENT_5_NAME, Gender.MALE, accounts[4]) };
    }

    public static void main(String[] args) {
	Bank bank = new Bank();
	initBank(bank);
	modifyBank(bank);
	BankService.printBalance(bank);
	BankService.printMaximumAmountToWithdraw(bank);
    }

    public static void modifyBank(Bank bank) {
	Account account = getClientAccount(bank, CLIENT_5_NAME);
	account.deposit(1000000.00);
	account = getClientAccount(bank, CLIENT_1_NAME);
	account.withdraw(140000.00);
	account = getClientAccount(bank, CLIENT_3_NAME);
	account.withdraw(140000.00);
	account = getClientAccount(bank, CLIENT_2_NAME);
	account.withdraw(19400.00);
    }

    private static Account getClientAccount(Bank bank, String clientName) {
	Client client = bank.getClient(clientName);
	return client.getAccount();
    }

    static void initBank(Bank bank) {
	for (Client client : clients) {
	    BankService.addClient(bank, client);
	}
    }

    /**
	 * 
	 */

}
